package com.cr.admin.business.driverlicense.controller;

import com.cr.admin.business.authentication.pojo.dto.param.AuthenticationUpdateParam;
import com.cr.admin.business.authentication.pojo.dto.query.AuthenticationQuery;
import com.cr.admin.business.authentication.pojo.vo.AuthenticationVO;
import com.cr.admin.business.driverlicense.pojo.dto.param.DriverLicenseSaveParam;
import com.cr.admin.business.driverlicense.pojo.dto.param.DriverLicenseUpdateParam;
import com.cr.admin.business.driverlicense.pojo.dto.query.DriverLicenseQuery;
import com.cr.admin.business.driverlicense.pojo.entity.DriverLicense;
import com.cr.admin.business.driverlicense.pojo.vo.DriverLicenseVO;
import com.cr.admin.business.driverlicense.service.DriverLicenseService;
import com.cr.common.response.JsonResult;


import com.cr.common.response.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "驾照管理")
@RequestMapping("/api/bus/users/driverlicense")
public class DriverLicenseController {
    @Autowired
    private DriverLicenseService driverLicenseService;
    @ApiOperation(value = "查询驾照")
    @GetMapping("{id}")
    public JsonResult getDriverLicenseDetail(@PathVariable Long id){
        DriverLicenseVO driverLicenseVO = driverLicenseService.getDriverLicenseDetail(id);
        return JsonResult.success(driverLicenseVO);
    }

    @ApiOperation(value = "新增驾照")
    @PostMapping
    public JsonResult addDriverLicense(@Validated @RequestBody DriverLicenseSaveParam driverLicenseSaveParam){
        driverLicenseService.addDriverLicense(driverLicenseSaveParam);
        return JsonResult.success();
    }

    @ApiOperation(value = "查询驾照列表")
    @GetMapping
    public JsonResult list(DriverLicenseQuery driverLicenseQuery) {
        PageData<DriverLicenseVO> pageData = PageData.page(driverLicenseQuery.getPageNum(), driverLicenseQuery.getPageSize(), () -> driverLicenseService.list(driverLicenseQuery));
        return JsonResult.success(pageData);
    }

    @ApiOperation(value = "修改驾照")
    @PutMapping()
    public JsonResult update(@Validated @RequestBody DriverLicenseUpdateParam driverLicenseUpdateParam) {
        driverLicenseService.updateById(driverLicenseUpdateParam);
        return JsonResult.success();
    }

    @ApiOperation(value = "删除驾照")
    @DeleteMapping()
    public JsonResult delete(@RequestParam(name = "ids") List<Long> ids){
        driverLicenseService.deleteByIds(ids);
        return JsonResult.success();
    }





}
